# Maintainer: J. Peter Mugaas <jpmugaas@suddenlink.net>

_realname=libimagequant
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=2.12.6
pkgrel=1
pkgdesc="Palette quantization library (mingw-w64)"
arch=('any')
url='https://github.com/ImageOptim/libimagequant'
license=("GPL3" "MIT")
source=("${_realname}-${pkgver}.tar.gz"::"https://github.com/ImageOptim/${_realname}/archive/${pkgver}.tar.gz"
        "0001-min-build-fix.patch")
sha256sums=('b34964512c0dbe550c5f1b394c246c42a988cd73b71a76c5838aa2b4a96e43a0'
            '9e8833679949ec2e51d9ccdc7005262898de02ba4a8f5f8463e07501c6878447')

prepare() {
  cd $srcdir/${_realname}-${pkgver}
#  patch -p1 -i ${srcdir}/0001-min-build-fix.patch
}

build() {
  cd "$srcdir"/${_realname}-${pkgver}
  rm -rf "${srcdir}"/build-${CARCH} || true
  cp -r "${srcdir}/${_realname}-${pkgver}" "${srcdir}/build-${CARCH}"
  cd "${srcdir}"/build-${CARCH}
  msg2 "PWD $(pwd)"
  if [ "${CARCH}" = "i686" ]; then
    SSE="--disable-sse"
  else
    SSE="--enable-sse"
  fi
  ./configure --prefix=${MINGW_PREFIX} \
    CC="${MINGW_PREFIX}/bin/gcc" \
    ${SSE}
  make --jobs=1 static dll imagequant.pc
}

package() {
  cd "${srcdir}"/build-${CARCH}
   mkdir -p ${pkgdir}${MINGW_PREFIX}/bin
   mkdir -p ${pkgdir}${MINGW_PREFIX}/lib/pkgconfig
   mkdir -p ${pkgdir}${MINGW_PREFIX}/include
   mkdir -p ${pkgdir}${MINGW_PREFIX}/share/doc/libimagequant
   mkdir -p ${pkgdir}${MINGW_PREFIX}/share/licenses/libimagequant
   install -m 0644 -p imagequant.dll \
     ${pkgdir}${MINGW_PREFIX}/bin/imagequant.dll
   install -m 0644 -p libimagequant.a \
     ${pkgdir}${MINGW_PREFIX}/lib/libimagequant.a
   install -m 0644 -p imagequant_dll.a \
     ${pkgdir}${MINGW_PREFIX}/lib/libimagequant.dll.a
   install -m 0644 -p libimagequant.h \
      ${pkgdir}${MINGW_PREFIX}/include/libimagequant.h
   install -m 0644 -p imagequant.pc \
       ${pkgdir}${MINGW_PREFIX}/lib/pkgconfig/imagequant.pc
   install -m 0644 -p CHANGELOG \
      ${pkgdir}${MINGW_PREFIX}/share/doc/libimagequant/CHANGELOG
   install -m 0644 -p README.md \
      ${pkgdir}${MINGW_PREFIX}/share/doc/libimagequant/README.md
   install -m 0644 -p COPYRIGHT \
       ${pkgdir}${MINGW_PREFIX}/share/licenses/libimagequant/COPYRIGHT
}

